{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
<style type="text/css">
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            {include file="public/topsection"}
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="fixed-table-toolbar" style="text-align: center;margin-bottom: 20px">
                        <h2>总金额: <font color="#1ab394">{$sum}</font></h2>
                    </div>
                    <div class="fixed-table-toolbar">
                        <a class="btn btn-default btn-outline {present name="types"}{else /}asdlkjasd{/present}"
                        href="{:url('order')}">所有</a>
                        <a class="btn btn-default btn-outline {eq name='types' value='1'}asdlkjasd{/eq}"
                           href="{:url('order',['types'=>'1'])}">红包</a>
                        <a class="btn btn-default btn-outline {eq name='types' value='2'}asdlkjasd{/eq}"
                           href="{:url('order',['types'=>'2'])}">连麦</a>
                        <a class="btn btn-default btn-outline {eq name='types' value='4'}asdlkjasd{/eq}"
                           href="{:url('order',['types'=>'4'])}">礼物</a>
                        <a class="btn btn-default btn-outline {eq name='types' value='5'}asdlkjasd{/eq}"
                           href="{:url('order',['types'=>'5'])}">座驾</a>
                        <a class="btn btn-default btn-outline {eq name='types' value='6'}asdlkjasd{/eq}"
                           href="{:url('order',['types'=>'6'])}">VIP</a>
                        <span style="float:right">
                            
                        <a class="btn btn-default btn-outline {eq name='order' value='id'}asdlkjasd{/eq}"
                           href="{:url('order',['order'=>'id'])}{present name='types'}/types/{$types}{/present}">默认排序</a>
                        <a class="btn btn-default btn-outline {eq name='order' value='money'}asdlkjasd{/eq}"
                           href="{:url('order',['order'=>'money'])}{present name='types'}/types/{$types}{/present}">金额倒序</a>
                        </span>
                    </div>
                    <div style="display:block;clear: both;"></div>
                    <div class="fixed-table-toolbar">
                        <form method="get" action="" style="display: flex;">
                            <div class="pull-left search" style="display: flex;">
                                <div class="columns columns-right btn-group pull-left">
                                    <select class="form-control" name="search">
                                        <option value="user_id" {php}if(input(
                                        '?param.search')){if(input('param.search')=='user_id'){echo "selected";}
                                        }{/php}>用户id</option>
                                        <option value="number" {php}if(input(
                                        '?param.search')){if(input('param.search')=='number'){echo "selected";}
                                        }{/php}>订单号</option>
                                        <option value="id" {php}if(input(
                                        '?param.search')){if(input('param.search')=='id'){echo "selected";}
                                        }{/php}>订单id</option>
                                        {eq name='types' value='4'}
                                        <option value="toid" {php}if(input(
                                        '?param.search')){if(input('param.search')=='toid'){echo "selected";}
                                        }{/php}>接收方id</option>
                                        {/eq}
                                    </select>
                                </div>

                                <div class="pull-right search">
                                    <input class="form-control input-outline" type="text"
                                           {php}
                                           if(input('?param.name')){
                                    if(input('param.name')){
                                    echo "value='".input('name')."'";
                                    }

                                    }
                                    {/php}
                                    name="name" placeholder="可输入双方ID，用,隔开">
                                </div>

                                <div class="pull-right search">
                                    <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px"
                                            class="btn btn-default btn-outline" type="submit">搜索
                                    </button>
                                </div>

                                <input name="start" type="text" id="start" class="form-control layui-input" value="{present name='start'}{$start}{/present}" placeholder=" # 起始时间" autocomplete="off" style="height:34px;width:155px;margin:0 10px;">
                                <input name="end" type="text" id="end" class="form-control layui-input" value="{present name='end'}{$end}{/present}" placeholder=" # 结束时间" autocomplete="off" style="height:34px;width:155px;margin:0 10px;">

                                {php}
                                if(input('?param.name')){
                                {/php}
                                <div class="pull-right search">
                                    <a class="btn btn-w-m btn-link" href="{:url('order')}">返回列表</a>
                                </div>
                                {php}
                                }
                                {/php}
                            </div>
                        </form>
                    </div>
                    <div class="example">
                        <form class="form-horizontal" method="post">
                            <table data-toggle="table">
                                <thead>
                                <tr>
                                    <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                                    <th data-align="center">ID</th>
                                    <th data-align="center">类型</th>
                                    <th data-align="center">用户</th>
                                    <th data-align="center">单号</th>
                                    {eq name='types' value='4'}
                                    <th data-align="center">接收方</th>
                                    {/eq}
                                    {eq name='types' value='2'}
                                    <th data-align="center">通话对象</th>
                                    {/eq}
                                    <th data-align="center">金额</th>
                                    <th data-align="center">方式</th>
                                    <th data-align="center">状态</th>
                                    {eq name='types' value='4'}
                                    <th data-align="center">聊天记录</th>
                                    {/eq}
                                    <th data-align="center">创建时间</th>
                                    <th data-align="center">更新时间</th>
                                    <th data-align="center">管理</th>
                                </tr>
                                </thead>
                                <tbody id="form">
                                {volist name="data" id="v"}
                                <tr id="id{$v.id}" class="class">
                                    <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                                    <td>{$v.id}</td>
                                    <td>
                                        {switch name="v.types"}
                                            {case value="1"}红包{/case}
                                            {case value="2"}连麦{/case}
                                            {case value="4"}礼物{/case}
                                            {case value="5"}座驾{/case}
                                            {case value="6"}VIP{/case}
                                            {default /}其他
                                        {/switch}
                                    </td>
                                    <td>{$v.name}<br/><a onclick="member('{$v.user_id}')" style="color:#40BCF7">{$v.user_id}</a></td>
                                    <td>{$v.number}</td>
                                    {in name='types' value='2,4'}
                                    <td>{$v.touser?$v.touser.name:''}<br/><a onclick="member('{$v.touserid}')" style="color:#40BCF7">{$v.touserid}</a></td>
                                    {/in}
                                    <td>{$v.money|number_format}</td>
                                    <td>
                                        {switch name="v.pays"}
                                            {case value="1"}余额{/case}
                                            {case value="2"}支付宝{/case}
                                            {case value="3"}微信{/case}
                                            {default /}微信
                                        {/switch}
                                    </td>
                                    <td>
                                        {switch name="v.status"}
                                        {case value="-1"}失效{/case}
                                        {case value="0"}待付{/case}
                                        {default /}完成
                                        {/switch}
                                    </td>
                                    {eq name='types' value='4'}
                                    <td><a onclick="chat('{$v.user_id},{$v.touserid}')" style="color:#40BCF7">{$v.chatid}</td>
                                    {/eq}
                                    <td>{$v.create_time|date='Y-m-d H:i',###}</td>
                                    <td>{$v.update_time|date='Y-m-d H:i',###}</td>
                                    <td>
                                        <div class="btn-group">
                                            <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">
                                                操作 <span class="caret"></span>
                                            </div>
                                            <ul class="dropdown-menu">
                                                <li><a onClick="del('{$v.id}')">删除</a>
                                                </li>
                                    {eq name='types' value='2'}
                                                <li><a onclick='showOrderDetail({php}echo $v['data'];{/php})'>查看订单数据</a>
                                                </li>
                                    {/eq}
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                {eq name='types' value='2'}
                <div class="col-sm-6">
                    <div  class="btn btn-outline btn-default" onclick="exports(0)">
                        导出
                    </div>
                </div>
                {/eq}
                <div class="col-sm-12 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>

<div id="OrderDetail" style="text-align:center;display:none;margin: 0px 30px;padding:10px 100px">
</div>
{include file="public/footer" /}
{load href="__PLUGINS__iCheck/icheck.min.js"}
{load href="__PLUGINS__iCheck/custom.css"}

<script type="text/javascript">

    $(document).ready(function(){
        $('#desAll').click(function(){
            var des=$(".form-horizontal").serialize();
            ajaxFun("post",'{:url("desAll")}',des,'json',function(ret){
                if(ret){
                    if(ret.ret){
                        self.location.reload();
                    }else{
                        layer.msg(ret.err)
                    }
                }else{
                    swal_msg("错误",ret,"error");
                }
            })
        })

    });

    layui.use(['laydate'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });
    })

    function del(id) {
        swal_del(id, "{:url('delorder')}")
    }
    function member(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("member/index")}?search=id&name='+id
            });
        });
    }

    function chat(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("usertalk/records")}?type=2&search=userid&name='+id
            });
        });
    }

    var downing = false

    function exports(sex) {

        if(downing){
            return layer.msg('导出进程较慢，请勿频繁点击');
        }
        downing = true
        setTimeout(()=>{
            downing = false
        }, 10000)
        let exportUrl = '{:url("Export/LianmaiOrder")}?order={$order}&start={$start}&end={$end}&search={$search}&name={$name}';
        try{
            window.open(exportUrl);
        }catch(e){
            window.location.href = exportUrl;
        }
    }
function formatTimeMills(timeMills){
    var date = new Date(timeMills);
    var timeStr = '';
    timeStr += date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours();
    timeStr += ':';
    timeStr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes();
    timeStr += ':';
    timeStr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds();
    return timeStr;
}
    function showOrderDetail(orderData) {
        let html = ''
        if (orderData.end && orderData.end > orderData.start) {
            html += `<div class="form-control">计费开始时间：<span style="font-weight:bold;">${formatTimeMills(orderData.start*1000)}</span></div>`
            html += `<div class="form-control">计费结束时间：<span style="font-weight:bold;">${formatTimeMills(orderData.end*1000)}</span></div>`
            html += `<div class="form-control">通话时长：<span style="font-weight:bold;">${orderData.end - orderData.start}秒</span></div>`
            html += `<div class="form-control">计费时长：<span style="font-weight:bold;">${orderData.duration}分钟</div>`
        } else {
            html += `<div class="form-control">通话时长：<span style="font-weight:bold;">0秒</span></div>`
        }
        html += `<div class="form-control">单价：<span style="font-weight:bold;">${orderData.price}</span></div>`
        if (orderData.duration) {
            html += `<div class="form-control">扣费金币：<span style="font-weight:bold;">${orderData.money}</span></div>`
            html += `<div class="form-control">产生积分：<span style="font-weight:bold;">${orderData.score}</span></div>`
        }
        html += `<div class="form-control">首次扣费秒数：<span style="font-weight:bold;">${orderData.first_second}</span></div>`
        html += `<div class="form-control">支付方IP：<span style="font-weight:bold;">${orderData.ip}</span></div>`
        html += `<div class="form-control">是否私密通话：<span style="font-weight:bold;">${orderData.privacy?'是':'否'}</span></div>`
        html += `<div class="form-control">对方ID：<span style="font-weight:bold;">${orderData.another_id}</span></div>`

        $('#OrderDetail').html(html)
        var index = layer.open({
            area: ['500px', '500px'],
            type: 1,
            title: '订单原始数据',
            content: $('#OrderDetail'),
            btn: ['确定'],
            yes: function (index, layero) {
                layer.close(index);
            }
        })
    }
</script>
 